Crate inksac

source ·
Expand description

Component-Based Terminal Colorization Library

This crate facilitates the coloring of terminal text output through a component-based system. You can define various styles and apply them to strings, then print them to the terminal, all while enjoying type safety and composability.

Steps to Use

  1. Predefine Your Styles: Before anything else, set up your styles using Style or with the builder pattern using StyleBuilder.
  2. Create Colored Strings: Using the predefined styles, create colored strings with ColoredString, or use the Stylish trait.
  3. Print the Colored String: Print the ColoredString instances just as you would with regular strings.

Example

Below is an example that demonstrates the usage of this crate, including utilizing the builder pattern for creating styles:

use inksac::{self, Color, ColoredString, Style};

match inksac::is_color_available() {
    Ok(_) => println!("Terminal supports ANSI colors"),
    Err(_) => println!("Terminal does not support ANSI colors"),
}

// Step 1: Predefine Your Styles using the builder pattern
let title_style = Style::builder()
    .foreground(Color::Green)
    .background(Color::Red)
    .underline()
    .build();

// Step 2: Create Colored Strings
let title_text: ColoredString = ColoredString::new(
    "Hello World",
    title_style,
);

// Step 3: Print the Colored String
println!("{}", title_text);

Please make sure your terminal supports ANSI colors by using the is_color_available function before attempting to print colored text.

Modules

Structs

  • String with the colored text
  • A struct representing various styles that can be applied to a string.
  • A builder struct for constructing a Style instance with various configurations.

Enums

  • Represents the different colors that can be used for text foreground and background styling.

Traits

  • Trait for types that can be styled with a Style

Functions